﻿using System;

namespace ChainOfResponsibility;

public class PurchaseRequest(double amount, string name)
{
    public double Amount { get; } = amount;
    public string ProductName { get; } = name;
}

public abstract class Approver(string name)
{
    public Approver? NextApprover { set; get; }
    protected string Name { get; } = name;
    public abstract void ProcessRequest(PurchaseRequest request);
}

public class Manager(string name) : Approver(name)
{
    public override void ProcessRequest(PurchaseRequest request)
    {
        if (request.Amount < 10000.0)
        {
            Console.WriteLine($"{Name}批准了采购{request.ProductName}的请求");
        }
        else
        {
            NextApprover?.ProcessRequest(request);
        }
    }
}

public class VicePresident(string name) : Approver(name)
{
    public override void ProcessRequest(PurchaseRequest request)
    {
        if (request.Amount < 25000.0)
        {
            Console.WriteLine($"{Name}批准了采购{request.ProductName}的请求");
        }
        else
        {
            NextApprover?.ProcessRequest(request);
        }
    }
}

public class President(string name) : Approver(name)
{
    public override void ProcessRequest(PurchaseRequest request)
    {
        Console.WriteLine(request.Amount < 100000.0 ? $"{Name}批准了采购{request.ProductName}的请求" : $"需要公司开会讨论");
    }
}

public static class Program
{
    public static void Main()
    {
        var requestPrinters = new PurchaseRequest(4000.0, "打印机");
        var requestSoftware = new PurchaseRequest(10000.0, "Maya");
        var requestComputers = new PurchaseRequest(40000.0, "电脑");

        Approver level1 = new Manager("项目主管");
        Approver level2 = new VicePresident("副总经理");
        Approver level3 = new President("总经理");

        level1.NextApprover = level2;
        level2.NextApprover = level3;

        level1.ProcessRequest(requestPrinters);
        level1.ProcessRequest(requestSoftware);
        level1.ProcessRequest(requestComputers);
    }
}